package leetcode.秋招.爱奇艺;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/1 14:44
 * @description：
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String next = in.next();
        next = next.substring(1, next.length() - 1);
        int[] ans = new int[0];
        if (next.length() == 0) {
            System.out.println(Arrays.toString(ans));
            return;
        }
        String[] split = next.split(",");
        ans = new int[split.length];
        List<Integer> stack = new ArrayList<>();
        Arrays.fill(ans, -1);
        int[] nums = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        for (int i = 0; i < nums.length; i++) {
            int cur = nums[i];
            if (cur > 0) {
                if (stack.contains(cur)) {
                    System.out.println(Arrays.toString(new int[0]));
                    return;
                }
                stack.add(cur);
                continue;
            }
            if (stack.size() > 0){
                change(stack, ans, nums, i);
            }
        }
        System.out.println(Arrays.toString(ans));
    }

    private static void change(List<Integer> stack, int[] ans, int[] nums, int i) {
        int min = Integer.MAX_VALUE;
        int tar = 0;
        int j = 0;
        int[] ints = Arrays.copyOfRange(nums, i, nums.length);
        for (int k = 0; k < stack.size(); k++) {
            int integer = stack.get(k);
            int i1 = binarySearch(ints, integer);
            if (i1 < min) {
                min = i1;
                tar = ints[i1];
                j = k;
            }
        }
        if (min == Integer.MAX_VALUE) {
            ans[i] = stack.get(stack.size() - 1);
            stack.remove(stack.size() - 1);
            return;
        }
        ans[i] = tar;
        stack.remove(j);
    }

    private static int binarySearch(int[] nums, int tar) {
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == tar) return i;
        }
        return Integer.MAX_VALUE;
    }
}
